﻿namespace Windows32
{
    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;

    public class User32
    {
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool AnimateWindow(int hWnd, uint dwTime, uint dwFlags);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int BeginPaint(int hWnd, ref PAINTSTRUCT ps);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool ClientToScreen(int hWnd, ref POINT pt);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool DispatchMessage(ref MSG msg);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool DrawFocusRect(int hWnd, ref RECT rect);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool EndPaint(int hWnd, ref PAINTSTRUCT ps);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int GetDC(int hWnd);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int GetFocus();
        public static int GetHeightOrder(uint intValue)
        {
            return (int) ((intValue & -65536) >> 0x10);
        }

        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool GetInputState();
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern ushort GetKeyState(int virtKey);
        public static int GetLowOrder(uint intValue)
        {
            return (((int) intValue) & 0xffff);
        }

        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int GetParent(int hWnd);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int GetSystemMetrics(int nIndex);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int GetWindowLong(int hWnd, int nIndex);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool GetWindowRect(int hWnd, ref RECT rect);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool HideCaret(int hWnd);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool InvalidateRect(int hWnd, ref RECT rect, bool erase);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int InvertRect(int hdc, ref RECT vRect);
        public static int InvertRect(int hdc, int x, int y, int width, int height)
        {
            RECT vRect = new RECT();
            vRect.left = x;
            vRect.top = y;
            vRect.right = x + width;
            vRect.bottom = y + height;
            return InvertRect(hdc, ref vRect);
        }

        public static bool isKeyMessage(int intMessage)
        {
            return (((intMessage == 0x100) || (intMessage == 0x101)) || (intMessage == 0x102));
        }

        public static bool isMouseDownMessage(int intMessage)
        {
            return ((((intMessage == 0x201) || (intMessage == 0x207)) || ((intMessage == 0x204) || (intMessage == 0x20b))) || (((intMessage == 0xa1) || (intMessage == 0xa7)) || ((intMessage == 0xa4) || (intMessage == 0xab))));
        }

        public static bool isMouseMoveMessage(int intMessage)
        {
            return ((intMessage == 0x200) || (intMessage == 160));
        }

        public static bool isMouseUpMessage(int intMessage)
        {
            return ((((intMessage == 0x202) || (intMessage == 520)) || ((intMessage == 0x205) || (intMessage == 0x20c))) || (((intMessage == 0xa2) || (intMessage == 0xa8)) || ((intMessage == 0xa5) || (intMessage == 0xac))));
        }

        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int LoadCursor(int hInstance, uint cursor);
        public static Point MousePosFromMessage(int intMessage, int Hwnd, uint lParam)
        {
            bool flag = true;
            if ((((intMessage == 0xa1) || (intMessage == 0xa7)) || ((intMessage == 0xa4) || (intMessage == 0xab))) || (((intMessage == 0xa2) || (intMessage == 0xa8)) || (((intMessage == 0xa5) || (intMessage == 0xac)) || (intMessage == 160))))
            {
                flag = false;
            }
            POINT pt = new POINT();
            pt.x = (short) (lParam & 0xffff);
            pt.y = (short) ((lParam & -65536) >> 0x10);
            if (flag)
            {
                ClientToScreen(Hwnd, ref pt);
            }
            return new Point(pt.x, pt.y);
        }

        public static Point MousePositionFromMSG(MSG msg)
        {
            POINT pt = new POINT();
            pt.x = (short) (msg.lParam & 0xffff);
            pt.y = (short) ((msg.lParam & -65536) >> 0x10);
            ClientToScreen(msg.hwnd, ref pt);
            return new Point(pt.x, pt.y);
        }

        public static Point MousePositionFromMSG(int hwnd, uint lParam)
        {
            POINT pt = new POINT();
            pt.x = (short) (lParam & 0xffff);
            pt.y = (short) ((lParam & -65536) >> 0x10);
            ClientToScreen(hwnd, ref pt);
            return new Point(pt.x, pt.y);
        }

        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool MoveWindow(int hWnd, int x, int y, int width, int height, bool repaint);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool PostMessage(int hWnd, int Msg, uint wParam, uint lParam);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool ReleaseCapture();
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int ReleaseDC(int hWnd, int hDC);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool ScreenToClient(int hWnd, ref POINT pt);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern uint SendMessage(int hWnd, int Msg, uint wParam, uint lParam);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int SetActiveWindow(int hWnd);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int SetCursor(int hCursor);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int SetFocus(int hWnd);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int SetWindowLong(int hWnd, int nIndex, int newLong);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int SetWindowPos(int hWnd, int hWndAfter, int X, int Y, int Width, int Height, uint flags);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool SetWindowRgn(int hWnd, int hRgn, bool redraw);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool ShowCaret(int hWnd);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int ShowWindow(int hWnd, short cmdShow);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int bRetValue, uint fWinINI);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENTS tme);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool TranslateMessage(ref MSG msg);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool UpdateLayeredWindow(int hwnd, int hdcDst, ref POINT pptDst, ref SIZE psize, int hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool WaitMessage();
    }
}

